<template>
  <div>
    <el-input v-model="input" placeholder="输入组名" size="mini" style="width: 200px"></el-input>

    <el-button size="mini"  @click="selectBookname()">查询</el-button>

    <el-button size="mini"  @click="addbookView">新增</el-button>


    <template>
      <el-table
        :data="bookdata"
        border
        height="680"
        style="width: 100%;">
        <el-table-column
          prop="id"
          label="期刊id">
        </el-table-column>
        <el-table-column
          prop="name"
          label="期刊类">
        </el-table-column>

        <el-table-column
          prop="parentId"
          label="父类id">
        </el-table-column>


        <el-table-column  label="操作" width="100">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="addattr(scope.row)">修改</el-button>
            <el-button type="text" size="small" @click="deleteIp(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :currentPage=currentPage4
      :page-sizes="[100, 200, 300, 400]"
      :page-size=pageSize
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>



    <el-dialog title="新增期刊类" :visible.sync="dialogFormVisible" size="mini" style="width: 100%;height: 500px" :before-close="handleClose">
      <el-form :model="form" size="mini" :inline="true">
        <el-form-item label="期刊类：" :label-width="formLabelWidth" >
          <el-input v-model="form.name" ></el-input>
        </el-form-item>
        <el-form-item label="期刊父类：" :label-width="formLabelWidth" >
          <el-input v-model="form.parentId" ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false" size="mini">取 消</el-button>
        <el-button type="primary" @click="addBook()" size="mini"> 确 定</el-button>
      </div>
    </el-dialog>






  </div>
</template>

<script>


  import axios from 'axios';


  export default {
    name: 'HelloWorld',
    data() {
      return {
        bookdata:[],
        pageSize:100,
        dialogFormVisible:false,
        form:{},
        formLabelWidth:"180",
        input:"",
        total:0,
        fileList:[],
        upfileUrl:"",
        upfileUrlCover:"",
        currentPage4:1,
        pageSize:100,
        pageSize:100,
        updateTime:0,
      }
    },


    methods: {
      addbookView(){
        this.dialogFormVisible=true;
      },


      getPage(obj) {
        axios.post(process.env.BASE_API + 'audio/getMember', obj).then(respone => {
          this.bookdata = respone.data.member;
          this.total = respone.data.total;
        })
          .catch(error => {

          });


      },


      handleSizeChange(val) {
        this.pageSize = `${val}`;
        let pageSize = this.pageSize;
        let obj = {
          "currentPageNum": 1,
          "endIndex": 0,
          "pageSize": parseInt(pageSize),
          "total": 0
        }

        this.getPage(obj);
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.currentPage4 = `${val}`;


        let obj = {
          "currentPageNum":parseInt(this.currentPage4),
          "endIndex": 0,
          "pageSize": parseInt(this.pageSize),
          "total": 0
        }

        this.getPage(obj);

      },
      handleRemove(){

      },
      handlePreview(){

      },
      //查询
      selectBookname(){

        if(this.input==null|this.input==""){
          let obj = {
            "currentPageNum":parseInt(this.currentPage4),
            "endIndex": 0,
            "pageSize": parseInt(this.pageSize),
            "total": 0
          }
          axios.post(process.env.BASE_API + 'audio/getMember', obj).then(respone => {
            this.bookdata = respone.data.member;
            this.total = respone.data.total;
          })
            .catch(error => {

            });



          return ;
        }


        let obj={
          name:this.input
        }
        axios.post(process.env.BASE_API + 'audio/selectName', obj).then(respone => {
          this.bookdata = respone.data;
        }).catch(error => {

        });

      },
      addBook(){


        //记录书名
        let obj={mBookMagament:{name:this.form.name,createdate:this.updateTime,parentId:this.form.parentId},mPage:{"currentPageNum":parseInt(this.currentPage4),
            "endIndex": 0,
            "pageSize": parseInt(this.pageSize),
            "total": 0}};
        axios.post(process.env.BASE_API + 'audio/add', obj).then(respone => {

          this.bookdata = respone.data.member;



          console.log( this.upfileUrl +"   "+ this.upfileUrlCover);
       //   this.$refs.upload1.submit();
         // this.$refs.upload2.submit();
          this.dialogFormVisible=false;
        }).catch(error => {
          this.$message("新增错误");
          this.dialogFormVisible=false;
        });


        /*   axios.post(process.env.BASE_API + 'book/addbook', obj).then(respone => {
             this.bookdata = respone.data;
             dialogFormVisible=false;
           }).catch(error => {
             this.$message("新增错误");
             dialogFormVisible=false;
           });*/

        //   book/insertBook?data=



      },
      deleteIp(row){



        let obj={
          "mBookMagament":row,
          "mPage": {
            "currentPageNum": 1,
            "endIndex": 0,
            "pageSize": 10,
            "total": 0
          }
        }


        axios.delete(process.env.BASE_API + "audio/deleteByPrimaryKey", {data: obj}).then(respone => {
          this.bookdata = respone.data.member;
        })
          .catch(error => {

          })

      },
      handleClose(){

      }

    },


    mounted() {
      let obj = {
        "currentPageNum":parseInt(this.currentPage4),
        "endIndex": 0,
        "pageSize": parseInt(this.pageSize),
        "total": 0
      }
      this.getPage(obj);


    },




  }
</script>

<style scoped>



</style>
